package com.zzh.takeoutapp.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.PoiInfo;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.geocode.GeoCodeResult;
import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeOption;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zzh.takeoutapp.R;
import com.zzh.takeoutapp.activity.OrderCarDatelisActivity;
import com.zzh.takeoutapp.activity.SearchActivity;
import com.zzh.takeoutapp.activity.SelectShoppingAddressActivity;
import com.zzh.takeoutapp.activity.ShopCatActivity;
import com.zzh.takeoutapp.adapter.HomeFragmentAdapter;
import com.zzh.takeoutapp.base.BaseFragment;
import com.zzh.takeoutapp.config.Constants;
import com.zzh.takeoutapp.config.UrlConfig;
import com.zzh.takeoutapp.entity.HomeShopEntity;
import com.zzh.takeoutapp.event.NetMsgEvent;
import com.zzh.takeoutapp.map.LocationService;
import com.zzh.takeoutapp.model.HomeBean;
import com.zzh.takeoutapp.model.ModelUtil;
import com.zzh.takeoutapp.service.EventbusHelper;
import com.zzh.takeoutapp.service.ServiceUrl;
import com.zzh.takeoutapp.utils.DividerGridItemDecoration;
import com.zzh.takeoutapp.utils.LoadingUtil;
import com.zzh.takeoutapp.utils.NetWorkUtils;
import com.zzh.takeoutapp.utils.SPUtils;
import com.zzh.takeoutapp.view.DiscountsView;
import com.zzh.takeoutapp.view.FilterView;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

//防止item位置互换 //manager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);    // 设置布局管理一条数据占用几行，如果是头布局则头布局自己占用一行
/* layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {@Override public int getSpanSize(int postion) {if (postion < 8) {return 2;} else {return 1; } } });*/

/**
 * @author zzh
 * @Name:
 * @Description:
 * @date
 * @time
 * @copyright
 */
public class HomesFragment extends BaseFragment implements View.OnClickListener, OnRefreshListener, OnLoadmoreListener {
    @Bind(R.id.refreshLayout)
    RefreshLayout mRefreshLayout;
    @Bind(R.id.address)
    TextView address;
    @Bind(R.id.tv_empty_text)
    TextView tv_empty_text;
    @Bind(R.id.empty_text)
    NestedScrollView mEmptyLayout;//设置没有数据网络的情况
    @Bind(R.id.iv_shear)
    ImageView iv_shear;
    @Bind(R.id.discounts_view)
    DiscountsView discountsView;
    @Bind(R.id.view_filter_basic)
    FilterView realFilterView;
    @Bind(R.id.home_address)
    LinearLayout homeAddress;
    @Bind(R.id.recyclerView)
    RecyclerView recyclerView;
    @Bind(R.id.go_up)
    ImageView mFAButton;
    private int screenPosition = 0;
    private DiscountsView discView;
    private HomeFragmentAdapter rvAdapter;
    private LinearLayoutManager layoutManager;
    private boolean isFirsts;
    private boolean move = true;
    private int mIndex = 0;
    private boolean idonSortClick = false;//判断监听
    private boolean isClickListenerFisrt;
    public static final String HOMESALESVOLUME = "tvHomeSalesVolume";
    public static final String HOMEDISTANCE = "tvHomeDistance";
    public static final String HOMESCREEN = "lvHomeScreen";
    public HomeBean homeData;
    private int CURPAGE = 1;//加载页码
    private HomeShopEntity homeShopEntity;//列表数据
    private LocationService locationService;
    public List<PoiInfo> poiList;
    private String cityStr;
    private int ForResultCode = 1;
    private boolean isBottom = false;
    private int lastVisibleItem = 0;
    private LoadingUtil loadingUtil;
    private final String HOMES_FRAGMENT = "HomesFragment";
    private final String HOMES_FRAGMENT_HOMEBEAN = "HomesFragmentHomeBean";
    private final String CONDITION_SERVICE = "ConditionService";
    private final String ON_ITEM_CLICK = "onItemClick";
    private final String YOU_HUI_FILTER = "youhui_filter";
    private final String PEI_FILTER = "pei_filter";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        locationService = new LocationService(getActivity());
        locationService.registerListener(mListener);
        locationService.setLocationOption(locationService.getDefaultLocationClientOption());
        locationService.start();// 定位SDK
        loadingUtil = new LoadingUtil(getActivity());
    }

    @Override
    protected void onFragmentVisibleChange(boolean isVisible) {
        super.onFragmentVisibleChange(isVisible);
        if (true == isVisible) {
            /*if (mRefreshLayout != null && homeShopEntity.getData().getItems() == null && !mRefreshLayout.isRefreshing()) {
                mRefreshLayout.autoRefresh();
            }*/
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container) {
        View view = inflater.inflate(R.layout.activity_using_basic, container, false);
        ButterKnife.bind(this, view);
        layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        address.setText("定位中");
        return view;
    }

    @Override
    public void getsavedInstanceState(Bundle savedInstanceState) {
    }

    @Override
    public void initComponent(View view) {
        rvAdapter = new HomeFragmentAdapter(getActivity());
        mRefreshLayout.setOnRefreshListener(this);
        mRefreshLayout.setOnLoadmoreListener(this);
        mRefreshLayout.setDisableContentWhenRefresh(true);
        mRefreshLayout.setDisableContentWhenLoading(true);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.addItemDecoration(new DividerGridItemDecoration(getActivity(), 0, R.color.blue));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.addOnScrollListener(scrollListener);
    }

    @Override
    public void setListener() {
        rvAdapter.setmOnItemClickLitener(new HomeFragmentAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int postion) {
                Intent intent = new Intent(getActivity(), OrderCarDatelisActivity.class);
                intent.putExtra("shop_id", rvAdapter.getNormalGoodsTitls()
                        .get(postion).getWaimai().getShop_id());
                intent.putExtra("cate_id", rvAdapter.getNormalGoodsTitls()
                        .get(postion).getWaimai().getCate_id());
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View v, int postion) {
                //moveToPosition(0);
            }
        });
        rvAdapter.setOnSortClick(new HomeFragmentAdapter.TextSortOnClickListener() {
            @Override
            public void onSortClick(View v, int postion, boolean isFirst) {
                switch (v.getId()) {
                    case R.id.discounts_view://满减优惠
                        discView = (DiscountsView) v;
                        idonSortClick = false;
                        isClickListenerFisrt = true;
                        smoothMoveToPosition(4);
                        setColor(discountsView, postion);
                        break;
                }
            }

            @Override
            public void onSortClick(View v, int postion) {
                switch (v.getId()) {
                    case R.id.filter_view://综合排序
                        screenPosition = postion;
                        idonSortClick = true;
                        smoothMoveToPosition(3);
                        break;
                }
            }
        });
        discountsView.setOnDiscountClickListener(new DiscountsView.OnDiscountClickListener() {
            @Override
            public void onDiscountClick(int position) {
                if (isClickListenerFisrt == false) {
                    discView = rvAdapter.getTextHolder().getReal_filterView();
                }
                setColor(discView, position);
            }
        });
    }


    private void setColor(DiscountsView discView, int postion) {
        if (postion == 0) {
            discView.getTvHomeDiscounts().setBackgroundResource(R.color.yellow);
            discView.getTvHomeGratis().setBackgroundResource(R.color.font_black_6);
            discView.getTvHomeMerchant().setBackgroundResource(R.color.font_black_6);
        } else if (postion == 1) {
            discView.getTvHomeDiscounts().setBackgroundResource(R.color.font_black_6);
            discView.getTvHomeGratis().setBackgroundResource(R.color.yellow);
            discView.getTvHomeMerchant().setBackgroundResource(R.color.font_black_6);
        } else if (postion == 2) {
            discView.getTvHomeDiscounts().setBackgroundResource(R.color.font_black_6);
            discView.getTvHomeGratis().setBackgroundResource(R.color.font_black_6);
            discView.getTvHomeMerchant().setBackgroundResource(R.color.yellow);
        }
        realFilter();
    }

    @Override
    public void onAfterInit() {

    }


    private void smoothMoveToPosition(int n) {

        int firstItem = layoutManager.findFirstVisibleItemPosition();
        int lastItem = layoutManager.findLastVisibleItemPosition();
        if (n <= firstItem) {
            recyclerView.smoothScrollToPosition(n);
        } else if (n <= lastItem) {
            int top = recyclerView.getChildAt(n - firstItem).getTop();
            recyclerView.smoothScrollBy(0, top);
        } else {
            recyclerView.smoothScrollToPosition(n);
            move = true;
        }

    }

    private void move(int n) {
        if (n < 0 || n >= rvAdapter.getItemCount()) {
            Toast.makeText(getActivity(), "超出范围了", Toast.LENGTH_SHORT).show();
            return;
        }
        mIndex = n;
        recyclerView.stopScroll();
        moveToPosition(n);
        smoothMoveToPosition(n);

    }

    private void moveToPosition(int n) {
        //先从RecyclerView的LayoutManager中获取第一项和最后一项的Position
        int firstItem = layoutManager.findFirstVisibleItemPosition();
        int lastItem = layoutManager.findLastVisibleItemPosition();
        //然后区分情况
        if (n <= firstItem) {
            //当要置顶的项在当前显示的第一个项的前面时
            recyclerView.scrollToPosition(n);
        } else if (n <= lastItem) {
            //当要置顶的项已经在屏幕上显示时
            int top = recyclerView.getChildAt(n - firstItem).getTop();
            recyclerView.scrollBy(0, top);
        } else {
            //当要置顶的项在当前显示的最后一项的后面时
            recyclerView.scrollToPosition(n);
            //这里这个变量是用在RecyclerView滚动监听里面的
            move = true;
        }

    }

    private RecyclerView.OnScrollListener scrollListener = new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            lastVisibleItem = layoutManager.findLastVisibleItemPosition();
            int n = Math.abs(mIndex - layoutManager.findFirstVisibleItemPosition());
            if (n >= 3) {
                if (dy > 0) {
                    realFilterView.setVisibility(View.GONE);
                    if (screenPosition == 2) {
                        realFilterView.setVisibility(View.VISIBLE);
                        screenPosition = 0;
                    }
                    if (idonSortClick == true) {
                        realFilterView.setVisibility(View.VISIBLE);
                        idonSortClick = false;
                        if (screenPosition == 0) {
                            realFilterView.show(screenPosition);
                        } else {
                            realFilterView.show(screenPosition);
                        }
                    }
                } else {
                    realFilterView.setVisibility(View.VISIBLE);
                    idonSortClick = false;
                }
            } else if (n < 3) {
                realFilterView.setVisibility(View.GONE);
            }
            if (n >= 4) {
                discountsView.setVisibility(View.VISIBLE);
            } else if (n < 3) {
                discountsView.setVisibility(View.GONE);
            }
        }

        public void onScrollStateChanged(RecyclerView recyclerView,
                                         int newState) {
            if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                if (rvAdapter != null) {
                    isBottom = rvAdapter.getItemCount() - 1 == lastVisibleItem;
                }
            }
        }
    };

    private void getDataView(HomeShopEntity entity) {
        rvAdapter.setNormalGoodsTitls(entity.getData().getItems());
        rvAdapter.notifyItemChanged(5);
    }

    @Override
    public void onStart() {
        super.onStart();
        EventbusHelper.register(this);
    }


    @Override
    public void onStop() {
        EventbusHelper.unregister(this);
        locationService.unregisterListener(mListener); //注销掉监听
        locationService.stop(); //停止定位服务
        loadingUtil.stopShowLoading();
        super.onStop();
    }

    private void getdata(LatLng ll) {
        GeoCoder geoCoder = GeoCoder.newInstance();
        OnGetGeoCoderResultListener listener = new OnGetGeoCoderResultListener() {
            @Override
            public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
                if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
                    return;
                }
                poiList = result.getPoiList();
                SPUtils.saveString(getActivity(), Constants.ALL_LATITUDE, String.valueOf(poiList.get(0).location.latitude));
                SPUtils.saveString(getActivity(), Constants.ALL_LONGITUDE, String.valueOf(poiList.get(0).location.longitude));
                locationService.stop(); //停止定位服务
                if (poiList != null && poiList.size() > 0) {
                    if (getActivity().getIntent().getType() == null) {
                        loadingUtil.startShowLoading();
                    }
                    ServiceUrl.HomeServiceUrl(getActivity(),
                            String.valueOf(poiList.get(0).location.latitude),
                            String.valueOf(poiList.get(0).location.longitude), HOMES_FRAGMENT_HOMEBEAN);
                }
                if (poiList.size() != 0) {
                    address.setText(poiList.get(0).name);
                    cityStr = poiList.get(0).city;
                }

            }

            @Override
            public void onGetGeoCodeResult(GeoCodeResult result) {
                if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
                }
            }
        };
        geoCoder.setOnGetGeoCodeResultListener(listener);
        geoCoder.reverseGeoCode(new ReverseGeoCodeOption().location(ll));
    }

    /*****
     *
     * 定位结果回调，重写onReceiveLocation方法，
     *
     */
    private BDAbstractLocationListener mListener = new BDAbstractLocationListener() {

        @Override
        public void onReceiveLocation(BDLocation location) {
            if (null != location && location.getLocType() != BDLocation.TypeServerError) {
                locationService.stop(); //停止定位服务
                LatLng point = new LatLng(location.getLatitude(), location.getLongitude());
                getdata(point);
            } else {
                address.setText("定位失败");
            }
        }

    };

    @Override
    public void onDestroy() {
        super.onDestroy();
        rvAdapter.stopBanner();
    }

    @OnClick({R.id.discounts_view, R.id.home_address, R.id.go_up, R.id.iv_shear})
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.discounts_view:
                break;
            case R.id.go_up:
                startActivity(new Intent(getActivity(), ShopCatActivity.class));
                break;
            case R.id.home_address:
                Intent intent = new Intent(getActivity(), SelectShoppingAddressActivity.class);
                Bundle bundle = new Bundle();
                bundle.putParcelableArrayList("poiList", (ArrayList<? extends Parcelable>) poiList);
                intent.putExtras(bundle);
                intent.putExtra("address", cityStr);
                start_ActivityForResult(intent, ForResultCode);
                break;
            case R.id.iv_shear:
                startActivity(new Intent(getActivity(), SearchActivity.class));
                break;
        }
    }

    private void setColor() {
        if (discountsView != null && discView != null) {
            discountsView.getTvHomeDiscounts().setBackgroundResource(R.color.font_black_6);
            discountsView.getTvHomeGratis().setBackgroundResource(R.color.font_black_6);
            discountsView.getTvHomeMerchant().setBackgroundResource(R.color.font_black_6);
            discView.getTvHomeDiscounts().setBackgroundResource(R.color.font_black_6);
            discView.getTvHomeGratis().setBackgroundResource(R.color.font_black_6);
            discView.getTvHomeMerchant().setBackgroundResource(R.color.font_black_6);
        }
    }

    private void loadingColor() {
        CURPAGE = 1;
        realFilter();
        setColor();
        loadingUtil.startShowLoading();
    }

    private void realFilter() {
        realFilterView.getTvHomeSalesVolume()
                .setTextColor(getResources().getColor(R.color.font_black_5));
        realFilterView
                .getTvHomeDistance().setTextColor(getResources().getColor(R.color.font_black_5));
        if (rvAdapter != null) {
            rvAdapter.getNormalSort().getFilterView().getTvHomeSalesVolume()
                    .setTextColor(getResources().getColor(R.color.font_black_5));
            rvAdapter.getNormalSort().getFilterView().getTvHomeDistance()
                    .setTextColor(getResources().getColor(R.color.font_black_5));
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == ForResultCode && data != null) {
            String getKey = data.getStringExtra("getKey");
            if (getKey != null) {
                address.setText(getKey);
                loadingUtil.startShowLoading();
                initSeevice("", "", "", "juli");
            }
        }

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMsgEvent(NetMsgEvent event) {
        String _msgType = (String) event.getMsgType();
        JSONObject jsonObject = event.getMsgJSONObj();
        switch (_msgType) {
            case YOU_HUI_FILTER://优惠
                loadingColor();
                initSeevice(event.getErrorString(), "", "", "");
                break;
            case PEI_FILTER://配送
                loadingColor();
                initSeevice("", "", event.getErrorString(), "");
                break;
            case ON_ITEM_CLICK://综合排序
                loadingColor();
                loadingUtil.startShowLoading();
                initSeevice("", "", "", event.getErrorString());
                break;
            case HOMESALESVOLUME://销量
                CURPAGE = 1;
                idonSortClick = false;
                realFilterView.getTvHomeSalesVolume().setTextColor(getResources().getColor(R.color.color_red));
                realFilterView.getTvHomeDistance().setTextColor(getResources().getColor(R.color.font_black_5));
                loadingUtil.startShowLoading();
                screenPosition = 2;
                smoothMoveToPosition(3);
                setColor();
                initSeevice("", "", "", "juli");
                break;
            case HOMEDISTANCE://距离
                CURPAGE = 1;
                idonSortClick = false;
                realFilterView.getTvHomeSalesVolume().setTextColor(getResources().getColor(R.color.font_black_5));
                realFilterView.getTvHomeDistance().setTextColor(getResources().getColor(R.color.color_red));
                loadingUtil.startShowLoading();
                screenPosition = 2;
                smoothMoveToPosition(3);
                setColor();
                initSeevice("", "", "", "juli");
                break;
            case HOMESCREEN:
                screenPosition = 1;
                idonSortClick = true;
                if (event.getStatusCode() == 10) {
                    idonSortClick = false;
                }
                smoothMoveToPosition(3);
                break;
            case HOMES_FRAGMENT_HOMEBEAN://主页数据
                loaderData(jsonObject);
                break;
            case HOMES_FRAGMENT://商家数据
                loadingUtil.stopShowLoading();
                loaderListShopData(jsonObject);
                break;
            case CONDITION_SERVICE:
                initData(jsonObject);
                break;
            default:
                break;
        }
    }

    private void initData(JSONObject jsonObject) {
        if (jsonObject != null)
            if (jsonObject.optString("error").equals("0")) {
                JSONObject data = jsonObject.optJSONObject("data");
                JSONObject orderby = data.optJSONObject("orderby");
                JSONObject youhui = data.optJSONObject("youhui");
                JSONObject pei_type = data.optJSONObject("pei_type");
                JSONObject ts = data.optJSONObject("ts");
                Map<String, String> stringStringMap = getKey(orderby.toString());
                Map<String, String> youhuiMap = getKey(youhui.toString());
                Map<String, String> pei_typeMap = getKey(pei_type.toString());
                Map<String, String> tsMap = getKey(ts.toString());
                pei_typeMap.putAll(tsMap);
                realFilterView.setTag2list(pei_typeMap);
                realFilterView.setHistorylist(youhuiMap);
                realFilterView.setSizeTaglist(stringStringMap);
                realFilterView.setOnFilterClickListener(new FilterView.OnFilterClickListener() {
                    @Override
                    public void onFilterClick(int position) {
                        screenPosition = position;
                        if (screenPosition == 0) {
                            realFilterView.show(screenPosition);
                        } else {
                            realFilterView.show(screenPosition);
                        }
                        idonSortClick = false;
                    }
                });

            }
    }

    private Map<String, String> getKey(String cityStr) {
        Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
        Map<String, String> stringStringMap = gson.fromJson(cityStr, new
                TypeToken<Map<String, String>>() {
                }.getType());
        return stringStringMap;
    }

    private void setmRefreshLayout() {
        mRefreshLayout.finishRefresh();
        mRefreshLayout.finishLoadmore();
    }

    /**
     * 加载商家数据
     *
     * @param jsonObject
     */
    private void loaderListShopData(JSONObject jsonObject) {
        setmRefreshLayout();
        idonSortClick = false;
        if (jsonObject.optString("error").equals("0")) {
            homeShopEntity = ModelUtil.getHomeShopEntity(jsonObject);
            if (CURPAGE == 1) {
                getDataView(homeShopEntity);
            } else {
                rvAdapter.insert(homeShopEntity.getData().getItems(), rvAdapter.getItemCount() - 1);
            }
            if (homeShopEntity.getData().getItems() == null || homeShopEntity.getData().getItems().size() < 10) {
                mRefreshLayout.setLoadmoreFinished(false);
            } else {
                CURPAGE++;
            }
        } else {

        }

    }

    /**
     * 加载banna的数据
     *
     * @param jsonObject
     */
    private void loaderData(JSONObject jsonObject) {
        setmRefreshLayout();
        if (jsonObject != null)
            if (jsonObject.optString("error").equals("0")) {
                mEmptyLayout.setVisibility(View.GONE);
                recyclerView.setVisibility(View.VISIBLE);
                homeData = ModelUtil.getHomeData(jsonObject);
                rvAdapter.setHomeBeans(homeData);
                recyclerView.setAdapter(rvAdapter);
                ServiceUrl.ConditionService(getActivity(), CONDITION_SERVICE);
                initSeevice("", "", "", "juli");
            } else {
                mEmptyLayout.setVisibility(View.VISIBLE);
                recyclerView.setVisibility(View.GONE);
            }
    }

    @Override
    public void onRefresh(RefreshLayout refreshlayout) {
        CURPAGE = 1;
        if (NetWorkUtils.notNetWork(getActivity()) == false) {//没有网络
            mEmptyLayout.setVisibility(View.VISIBLE);
            recyclerView.setVisibility(View.GONE);
            refreshlayout.finishRefresh();
        } else {
            ServiceUrl.HomeServiceUrl(getActivity(),
                    SPUtils.getString(getActivity(),
                            Constants.ALL_LATITUDE, ""),
                    SPUtils.getString(getActivity(),
                            Constants.ALL_LONGITUDE, ""),
                    HOMES_FRAGMENT_HOMEBEAN);
        }

    }

    private void initSeevice(String youhui, String feature, String pei, String str) {
        Log.e("CURPAGE", CURPAGE + "");
        ServiceUrl.FiltrateServiceUrl(getActivity(),
                SPUtils.getString(getActivity(),
                        Constants.ALL_LATITUDE, ""),
                SPUtils.getString(getActivity(),
                        Constants.ALL_LONGITUDE, ""),
                youhui, feature, pei, "", str, CURPAGE, HOMES_FRAGMENT);
    }

    @Override
    public void onLoadmore(RefreshLayout refreshlayout) {
        initSeevice("", "", "", "juli");
    }
}
